#coding:utf-8

import json


def init_rss_source(filename):
	R = dict()
	with open(filename,mode='r') as f:
		for line in f:
			try:
				v,r = json.loads(line)
			except Exception,e:
				print e
				print line
				exit()
			R[r] = v
	return R

def getUri(m,rss_url):
	i = m['link']
	return i

from time import mktime
from datetime import datetime

def getData(m,rss_url):
	n = dict()
	n['link'] = m['link']
	n['title'] = m.get('title','')
	n['title_detail'] = m.get('title_detail','')
	n['summary'] = m.get('summary','')
	n['summary_detail'] = m.get('summary_detail','')
	n['authors'] = m.get('authors','')
	n['author_detail'] = m.get('author_detail','')
	n['published'] = m.get('published','')
	t = m.get('published_parsed')
	if t == None:
		t = datetime(2011,1,1)
	else:
		t = datetime.fromtimestamp(mktime(t))
	t = t.strftime('%Y-%m-%d %H:%M:%S')
	n['date'] = t
	c = datetime.now()
	c = c.strftime('%Y-%m-%d %H:%M:%S')
	n['current'] = c
	return n
